import request from "../request";
import qs from "qs";

interface AdminLoginParams {
    password: string,
    username: string,
}

// 设置返回值类型

// 类型参数化

interface AdminLoginResData {
    tokenHead:string,
    token:string,
}
interface AdminInfoResData {
    menus:MenusType[];
}

interface AdminListParams {
    keyword:string;
    pageNum:number;
    pageSize:number;
}

interface AdminListResData{
    list:{}[];
    total:number;
}

interface RoleUpdateParams {
    adminId: number;
    roleIds: string;
  }
//   interface RoleUpdateParams1 {
//     adminId: number;
//     roleIds: number[];
//   }


// 登录接口
export const adminLogin = (data:AdminLoginParams):PromiseRes<AdminLoginResData>=>request.post("/admin/login",data);
// 获取当前登录用户信息
export const getAdminInfo = ():PromiseRes<AdminInfoResData>=>request.get("/admin/info");
// 获取用户列表
export const getAdminList = (data:Partial<AdminListParams>):PromiseRes<AdminListResData>=>request.get("/admin/list",{params:data});
// 修改指定用户信息
export const getAdminUpdate = (data:AdminResDataObj):PromiseRes<unknown>=>request.post("/admin/update/" + data.id,data);
// 添加用户
export const registerAdmin = (data:AdminResDataObj):PromiseRes<unknown>=>request.post("/admin/register",data);

// 获取指定用户的角色列表
export const getAdminRoleById = (id: number): PromiseRes<{ id: number }[]> =>
  request.get("/admin/role/" + id);

// 给用户分配角色
export const updateAdminRole = (data: RoleUpdateParams): PromiseRes<unknown> =>
  request.post("/admin/role/update", null, { params: data });

// export const updateAdminRole1 = (
//   data: RoleUpdateParams1
// ): PromiseRes<unknown> => {
//   console.log(qs.stringify(data, { arrayFormat: "repeat" }));
//   return request.post(
//     "/admin/role/update",
//     qs.stringify(data, { arrayFormat: "repeat" })
//   );
// };
